package com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_adapter3;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;

import com.example.qingyiapp.R;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.Address_data_Activity;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv3;

import java.util.List;

public class adapter_address_lv3 extends BaseAdapter {

    List<JavaBean_lv3.DataBean> list;
    Context context;

    adapter_address_lv3_rv3.MyLintener myLintener;

    public void setMyLintener(adapter_address_lv3_rv3.MyLintener myLintener) {
        this.myLintener = myLintener;
    }

    public adapter_address_lv3(List<JavaBean_lv3.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }


    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        MyViewHolder myViewHolder = null;
        if(convertView==null){
            myViewHolder = new MyViewHolder();

            convertView = View.inflate(context, R.layout.address_rows3,null);
            myViewHolder.recyclerView = convertView.findViewById(R.id.address_rv3);

            convertView.setTag(myViewHolder);
        }else{
            myViewHolder = (MyViewHolder) convertView.getTag();
        }

        adapter_address_lv3_rv3 adapter_address_lv3_rv3 = new adapter_address_lv3_rv3(list.get(position).getList(),context);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        adapter_address_lv3_rv3.setMyLintener(new adapter_address_lv3_rv3.MyLintener() {
            @Override
            public void clickIntent(int pisition) {
                List<JavaBean_lv3.DataBean.ListBean> lists = list.get(position).getList();
                Intent intent = new Intent(context, Address_data_Activity.class);
                intent.putExtra("pid", lists.get(position).getPid());
                context.startActivity(intent);
            }
        });


        myViewHolder.recyclerView.setLayoutManager(linearLayoutManager);
        myViewHolder.recyclerView.setAdapter(adapter_address_lv3_rv3);

        return convertView;
    }

    class MyViewHolder{
            RecyclerView recyclerView;
    }
}
